﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WLYT.Application.Interfaces;
using WLYT.Domain.Model;
using WLYT.Domain.Model.HikModel;

namespace WLYT.WMS.Controllers
{
    [ApiController]
    public class AgvController(IAgvService agvService) : ControllerBase
    {
        [HttpPost]
        [Route("api/agv/agvCallbackService/agvCallback")]
        public async Task<HKAgvResponseModel> AgvCallback([FromBody] HKAgvRequestModel request)
        {
            HKAgvResponseModel resultModel = new HKAgvResponseModel() { reqCode = request.reqCode };
            try
            {
                switch (request.method)
                {
                    case "start":
                        //任务开始
                        await agvService.BindAgv(request.taskCode, request.agvCode);
                        break;

                    case "leaveBin":
                        //CTU走出储位
                        break;

                    case "end":
                    case "reachBin":
                    case "reachLine":
                        //任务完成
                        await agvService.Arrive(request.taskCode, request.mapDataCode);
                        break;

                    case "cancel":
                        //任务取消
                        //new AgvExec().UpdateStockRackWareTaskCancel(request.taskCode, request.mapDataCode, request.podCode);
                        break;

                    case "applyFromAgv":
                        //CTU出库料箱放申请 
                        //new AgvExec().ApplyFromAgv(request.taskCode);
                        break;
                }
            }
            catch (Exception ex)
            {
            }
            return resultModel;
        }

        [HttpPost]
        [Route("api/plc/DeviceStatus")]
        public Task<ApiResult> DeviceStatus([FromBody] PlcChangeModel model)
        {
            return agvService.DeviceStatus(model.PlcAddress, model.IsRun);
        }

        [HttpPost]
        [Route("api/plc/StatusChange")]
        public Task<ApiResult> StatusChange([FromBody] PlcChangeModel model)
        {
            return agvService.StatusChange(model.PlcAddress, model.Status, model.Size);
        }

        [HttpPost]
        [Route("api/plc/ActionCompleted")]
        public Task<ApiResult> ActionCompleted([FromBody] PlcChangeModel model)
        {
            return agvService.ActionCompleted(model.PlcAddress);
        }
    }
}
